<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./resrt.css">
    <style>
        #app{
            width: 400px;
            margin: 100px auto;
        }
        .top{
            height: 60px;
            padding: 10px;
            box-sizing: border-box;
            width: 100%;
            display: flex;
        }
        .top input{
            height: 40px;
            margin-top: 10px;
            border: 1px solid #eee;
            padding-left: 20px;
            width: 250px;
            
        }
        .top button{
            height: 40px;
            margin-top: 10px;
            flex: 1;
            margin-left: 20px;
        }
        .center{
            padding: 10px;
            height: 50px;
            display: flex;
            justify-content: space-between;
        }
        h2 , h3 , h4{
            width: 32%;
            line-height: 50px;
            text-align: center;
        }
        h2, h3{
            background-color: aqua;
        }
        h4{
            background-color: red;
        }
        h1{
            padding: 10px;
            font-size: 30px;
        }
        .bottom{
            padding: 10px;
        }
        .list{
            display: flex;
            height: 50px;
            background-color: cornflowerblue;
            justify-content: space-between;
            text-align: center;
            line-height: 50px;
            margin-top: 20px;
        }
        .change{
            background-color: blueviolet;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="top">
            <input type="text" placeholder="输入" v-model="from">
            <button @click="add">新增</button>
        </div>
        <div class="center">
            <h2>全部任务（{{list.length}}）</h2>
            <h3>已完成任务（{{finis()}}）</h3>
            <h4>未完成任务（{{undone()}}）</h4>
        </div>
        <h1>任务列表</h1>
        <div class="bottom">
            <div :class="`list ${item.state? 'change' : ''}`" v-for="(item , index) in list" :key="index">
                <input type="checkbox" @click="change(item)">
                <p>{{item.text}}</p>
                <button @click="sub(index)">删除</button>
            </div>
        </div>
    </div>
</body>
</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var num = 0
    var v = new Vue({
        el:'#app',
        data:{
            from:'',
            list:[

            ]
        },
        methods:{
            add(){
                num++
                if(this.from){
                    this.list.push({id:num , text : this.from , state : false})
                }
                this.from = ''
            },
            change(item){
                item.state = !item.state
            },
            sub(index){
                this.list.splice(index , 1)
            },
            undone(){
                var sum = 0
                this.list.map((item , index) => {
                    item.state ? '' : sum++
                })
                return sum
            },
            finis(){
                var sum = 0
                this.list.map((item , index) => {
                    item.state ? sum++ : ''
                })
                return sum
            }
        }
    })
</script>